#!/usr/bin/env python
# -*- coding: utf-8 -*-

"""Predesys Server - User Interface - Tools
@version: 0.2.5
@license: GPL 3.0 (see "license" file)
@author: Jose A. Jimenez
@contact: jajimc@gmail.com"""

import sys
sys.dont_write_bytecode = True

def get_parameter_value(argv, name):
    """Gets the value of a command line input argument.
    @param argv: Command line input data
    @type argv: C{list}
    @param name: Argument name
    @type name: C{str}
    @return: Parameter value
    @rtype: C{str}"""
    value = None
    length = len(argv)
    for i in range(0, length):
        item = argv[i].lower()
        if i < (length - 1) and item == ("-%s" % name):
            if argv[i + 1][0] != "-":
                value = argv[i + 1].replace(",", "")
                if (i + 1) < (length - 1):
                    for j in range(i + 2, length):
                        if argv[j][0] != "-":
                            value += (", " + argv[j].replace(",", ""))
                        else:
                            break
                break
                
    return value
